#!/bin/bash

echo "Running ROS2 Video Detection Camera Package..."

# 检查ROS2环境
if [ -z "$ROS_DISTRO" ]; then
    echo "Error: ROS2 environment not found. Please source ROS2 setup file first."
    echo "Example: source /opt/ros/humble/setup.bash"
    exit 1
fi

echo "ROS2 Distribution: $ROS_DISTRO"

# 检查编译好的程序是否存在
if [ ! -f "build/camera_node" ] || [ ! -f "build/video_det_node" ]; then
    echo "Error: Executables not found. Please build the project first:"
    echo "  ./build.sh"
    exit 1
fi

echo "Starting camera node..."
# 启动摄像头节点
./build/camera_node &
CAMERA_PID=$!

echo "Starting video detection node..."
# 启动视频检测节点
./build/video_det_node &
VIDEO_DET_PID=$!

echo "Both nodes started successfully!"
echo "Camera node PID: $CAMERA_PID"
echo "Video detection node PID: $VIDEO_DET_PID"
echo ""
echo "Press Ctrl+C to stop both nodes"

# 等待用户中断
trap "echo 'Stopping nodes...'; kill $CAMERA_PID $VIDEO_DET_PID; exit 0" INT

# 等待两个进程
wait
